<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="边帅">
    <title>轮播图</title>
    <style>
        .box {
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
        }

        ul {
            width: 170px;
            height: 100px;
            list-style: none;
            margin: 0;
            padding: 0;
        }

        li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }

        .cur {
            display: block;
        }

        .divs {
            width: 150px;
            display: flex;
            position: absolute;
            /* top: 200px; */
            /* left: 720px; */
            justify-content: center;
        }

        section {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: red;
        }

        .back {
            background-color: lawngreen;
        }

        .left {
            position: absolute;
            top: 80px;
            left: -70px;
        }

        .right {
            position: absolute;
            top: 80px;
            left: 200px;
        }

        div {
            width: 50px;
            height: 50px;
        }
    </style>
</head>

<body>

    <div class="box">
        <ul>
            <li><a href="#"><img src="01.jpg" alt=""></a></li>
            <li><a href="#"><img src="02.jpg" alt=""></a></li>
            <li><a href="#"><img src="03.jpg" alt=""></a></li>
            <li><a href="#"><img src="04.jpg" alt=""></a></li>
            <li><a href="#"><img src="05.jpg" alt=""></a></li>
        </ul>
        <div class="divs">
            <section></section>
            <section></section>
            <section></section>
            <section></section>
            <section></section>
        </div>

        <div class="left lu">左</div>
        <div class="right lu">右</div>

    </div>


    <script src="./jquery.js"></script>
</body>

</html>
<script>
    var lis = $('li');
    var index = 0;
    var section = $('section');
    var timer = setInterval(changeImage, 1000);
    function changeImage() {
        index++;
        if (index == 5) {
            index = 0;
        }
        section.eq(index).addClass('back').siblings().removeClass('back');
        lis.eq(index).css('display', 'block').siblings().css('display', 'none');
    }


    // 
    index = $(this).index();

    section.mouseover(function () {
        clearInterval(timer);
        index = $(this).index();
        $('li').eq(index).css('display', 'block').siblings().css('display', 'none');
        section.eq(index).addClass('back').siblings().removeClass('back');

    });
    section.mouseout(function () {
        timer = setInterval(changeImage, 1000);


    });


    $('.left').click(function () {
        clearInterval(timer);

        if (index == 0) {
            index = 4;
        } else {
            index = index - 1;
        }
        section.eq(index).addClass('back').siblings().removeClass('back');
        $('li').eq(index).css('display', 'block').siblings().css('display', 'none');
    });

    $('.right').click(function () {
        clearInterval(timer);
        if (index == 4) {
            index = 0;
        } else {
            index = index + 1;
        }
        section.eq(index).addClass('back').siblings().removeClass('back');
        $('li').eq(index).css('display', 'block').siblings().css('display', 'none');
    });

    $('.lu').hover(function () {
        clearInterval(timer);
    }, function () {
        timer = setInterval(changeImage, 1000);
    });

</script>